﻿using Microsoft.AspNetCore.Mvc;
using mozhi.smarterp.AuthorCenter.Users;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Identity;

namespace mozhi.smarterp.AuthorCenter.Controllers
{
    [Dependency(ReplaceServices = true)]
    [ExposeServices(typeof(IdentityUserController),IncludeSelf = true)]
    [ControllerName("User")]
    public class CustomIdentityUserController : IdentityUserController
    {
        private ICustomIdentityUserAppService _appService;

        public CustomIdentityUserController(ICustomIdentityUserAppService userAppService) : base(userAppService)
        {
            _appService = userAppService;
        }

        public override async Task<PagedResultDto<IdentityUserDto>> GetListAsync(GetIdentityUsersInput input)
        {
            var filter = new IdentityUserFilter();
            filter.Sorting= input.Sorting;
            filter.MaxResultCount = input.MaxResultCount;
            filter.SkipCount = input.SkipCount;
            filter.Filter = input.Filter;

            var typeParamter = HttpContext.Request.Query["userType"].ToString();

            int userType;
            if (int.TryParse(typeParamter, out userType))
                filter.UserType = userType;

            return await _appService.GetListAsync(filter);
        }

        [HttpGet]
        [Route("authorized-urls")]
        public async Task<List<UserAuthorizedUrlDto>> GetUserAuthorizedUrls()
        {
            return await _appService.GetUserAuthorizedUrlsAsync();
        }

       
    }
}
